<template>
    <div>
        <!-- 头部客户组简要信息 -->
        <div class="container user-basic-box e-m-h-auto e-m-b-15">
            <el-page-header @back="goBack" :content="details.parentid > 0?'部门详情':'客户组详情'"></el-page-header>
            <div class="user-face">
                <div class="avatar">
                    <el-avatar icon="el-icon-s-shop" :size="100"></el-avatar>
                </div>
            </div>
            <div class="name">
                {{ details.name }}{{ details.parentid > 0?'-'+details.department:'' }}
            </div>
            <div>
                <el-button type="text" size="small" icon="el-icon-edit" @click="edit">修改名称</el-button>
            </div>
            <!-- <div>
                <el-tag type="success" size="mini" v-if="details.user">已绑定</el-tag>
                <el-tag type="danger" size="mini" v-else>未绑定</el-tag>
            </div> -->
            <div class="basic flex">
                <div class="item"><i class="el-icon-document"></i><span>客户组编号：</span><span>{{ details.ysid }}</span></div>
                <div class="item"><i class="el-icon-alarm-clock"></i><span>注册时间：{{ details.regdate }}</span></div>
                <div class="item" v-if="details.franchise"><i class="el-icon-house"></i><span>所属加盟商：{{ details.franchise.name }}</span></div>
            </div>

            <div class="admin-statistics-content e-m-t-30">
                <div class="item e-flex-1">
                    <label>管理模式</label>
                    <div>
                        <span>{{ details.financemode}}</span>
                    </div>
                    <el-button v-if="details.parentid == 0" type="text" size="mini" icon="el-icon-edit" @click="changeMode">更换模式</el-button>
                </div>
                <div class="item e-flex-1">
                    <label>绑定账户</label>
                    <div v-if="details.user">
                        <div>
                            <!-- <span>{{ details.user.name }}({{ details.user.mobile }})</span> -->
                            <span><el-button type="text" @click="userViews(details.user)" class="e-p-t-0 e-p-b-0"><span class="e-font-16">{{ details.user.name }}({{ details.user.mobile }})</span></el-button></span>
                        </div>
                        <el-button type="text" size="mini" icon="el-icon-edit" @click="unbinding">解绑客户组</el-button>
                    </div>
                    <div v-else>
                        <div>
                            <span>未绑定</span>
                        </div>
                        <el-button type="text" size="mini" icon="el-icon-edit" @click="binding">绑定客户组</el-button>
                    </div>
                </div>
                <div class="item e-flex-1">
                    <label>所属地区</label>
                    <div v-if="editAddress == false"><span>{{ details.city.citynames || '--' }}</span></div>
                    <div class="e-flex-1" v-else>
                        <cityList @change="SelectSearchCity"></cityList>
                    </div>
                    <el-button type="text" size="small" icon="el-icon-edit" @click="editAddress = !editAddress">{{ editAddress?'返回':'修改地区' }}</el-button>
                </div>
            </div>
            <div class="admin-statistics-content e-m-t-30">
                <div class="item e-flex-1">
                    <label>账户余额</label>
                    <div>
                        <span class="e-font-20">{{ utils.formatMoney(details.balance) }}<span class="e-font-14">元</span></span>
                    </div>
                </div>
                <div class="item e-flex-1">
                    <label>累计提现</label>
                    <div>
                        <span class="e-font-20">{{ utils.formatMoney(-details.cashout) }}<span class="e-font-14">元</span></span>
                    </div>
                </div>
                <div class="item e-flex-1">
                    <label>账户积分</label>
                    <div>
                        <span class="e-font-20">{{ details.integral}}<span class="e-font-14">分</span></span>
                    </div>
                </div>
            </div>
        </div>
        <!--  -->
        <div class="container e-m-h-auto e-m-b-15">
            <div class="type-state e-m-b-30">
                <span v-for="(item, index) in tabsType" :key="index" :class="{ 'on': tab == item.value }" @click="tab = item.value">{{ item.name }}</span>
            </div>
            <div class="container-item" v-if="tab == 1">
                <!-- <el-tag class="e-m-l-5" v-if="operator.isproprietary" size="mini">自营</el-tag> -->
                <div class="container e-m-h-auto e-m-b-15">
                    <el-form label-width="auto">
                        <h4>客户组设置</h4>
                        <div class="flex">
                            <div class="e-flex-1">
                                <el-form-item label="账户管理模式:">
                                    <span class="e-m-r-10">{{ details.financemode }}</span>
                                    <el-button v-if="details.parentid == 0" type="primary" size="mini" @click="changeMode">更换模式</el-button>
                                </el-form-item>
                            </div>
                            <div class="e-flex-1">
                                <el-form-item label="客户组类型:">
                                    <el-select v-model="details.type" placeholder="请选择客户组类型" @change="updateEnterpriseType">
                                        <el-option v-for="item in typeArr" :key="item.value" :label="item.name" :value="item.value">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </div>
                            <div class="e-flex-1">
                                <el-form-item label="所属地区:">
                                    <div class="flex">
                                        <div v-if="editAddress == false" class="e-m-r-20"><span>{{ details.city.citynames || '--' }}</span></div>
                                        <div class="e-flex-1" v-else>
                                            <cityList @change="SelectSearchCity"></cityList>
                                        </div>
                                        <el-button type="text" size="small" icon="el-icon-edit" @click="editAddress = !editAddress">{{ editAddress?'返回':'修改地区' }}</el-button>
                                    </div>
                                </el-form-item>
                            </div>
                        </div>
                        <div class="flex">
                            <div class="e-flex-1">
                                <el-form-item label="每回收所得1元能获得积分:" v-if="operator.isproprietary">
                                    <el-input v-model="details.integralratio" type="number" placeholder="每回收所得1元能获得积分" class="e-w-300">
                                        <div slot="suffix" style="line-height: 2.8em;padding-right: 5px;">分</div>
                                        <el-button slot="append" @click="updateIntegralRatio">确定</el-button>
                                    </el-input>
                                </el-form-item>
                            </div>
                        </div>
                    </el-form>
                </div>
                <!-- 数据汇总 -->
                <div>
                    <div class="container e-m-h-auto e-m-b-15">
                        <h4>各品类回收汇总</h4>
                        <div class="e-p-b-15">
                            <el-form ref="form" :model="dateForm" label-width="100px" style="border-bottom: 1px solid var(--light);">
                                <el-form-item label="时间范围">
                                <el-radio-group v-model="dateForm.timeType" size="small" @input="chageTime">
                                    <el-radio-button v-for="(item,index) in dateForm.timeTypeArr" :key="index" :label="item.id">{{ item.name }}</el-radio-button>
                                </el-radio-group>
                                </el-form-item>
                                <el-form-item label="自定义日期" v-if="dateForm.timeType == 9">
                                    <el-date-picker size="small" v-model="dateForm.date" type="daterange" range-separator="至"
                                        start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" @change="chageTime"
                                        :picker-options="expireTimeOPtion" :unlink-panels="true">
                                    </el-date-picker>
                                </el-form-item>
                            </el-form>
                        </div>
                        <div></div>
                        <el-table ref="multipleTable" tooltip-effect="dark" :data="orderRecord.orderdetails" :span-method="objectSpanMethod" show-summary :summary-method="getSummaries" stripe border style="width: 100%;">
                            <el-table-column prop="large" label="类型" width="180">
                            </el-table-column>
                            <el-table-column prop="name" label="可回收物">
                            </el-table-column>
                            <el-table-column prop="weight" label="数量（KG/件）">
                                <template slot-scope="scope">
                                    <span v-if="scope.row.weight > 0">{{ scope.row.weight }}</span>
                                    <span v-else-if="scope.row.quantity > 0">{{ scope.row.quantity }}件</span>
                                    <span v-else>--</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="amount" label="金额（元）">
                            </el-table-column>
                        </el-table>

                        <h4>下级部门数据汇总</h4>
                        <div class="e-p-b-30">
                            <el-button type="primary" @click="downloadwithdrawa" plain><i class="iconfont icon-excel e-font-14 e-m-r-5"></i>导出Excel</el-button>
                        </div>
                        <el-table ref="multipleTable" tooltip-effect="dark" :data="statisticsTotal.details" show-summary stripe border style="width: 100%;">
                            <!-- <el-table-column prop="name" label="单位名称">
                            </el-table-column> -->
                            <el-table-column prop="department" label="部门">
                            </el-table-column>
                            <el-table-column prop="weight" label="回收重量(KG)">
                            </el-table-column>
                            <el-table-column prop="quantity" label="回收件数(件)">
                            </el-table-column>
                            <el-table-column prop="ordernumber" label="订单条数(条)">
                            </el-table-column>
                            <el-table-column prop="amount" label="回收总金额(元)">
                            </el-table-column>
                        </el-table>
                    </div>
                    <div class="container e-m-h-auto e-m-b-15">
                        <h4>最新订单</h4>
                        <orderUserList :enterpriseId="id" :franchiseId="details.franchise.id" :insidePage="false"></orderUserList>
                    </div>
                </div>
            </div>
            <div class="container-item" v-if="tab == 2">
                <!-- 下级部门 -->
                <enterpriseList v-if="tab == 2" :parentId="id"></enterpriseList>
            </div>
        </div>

        <!-- ====================================================== -->
        <!-- <div class="e-m-t-15"> -->
            <!-- <el-button @click="goBack">返回</el-button> -->
            <!-- <el-button type="primary" @click="onOopenPrinter">检测打印机</el-button>
            <el-button type="primary" @click="printMore">多选打印部门二维码</el-button>
            <el-button type="primary" @click="downloadMore" plain>多选下载部门二维码</el-button> -->
            <!-- <el-button type="primary" @click="goLog">查看用户日志</el-button> -->
        <!-- </div> -->

        <!-- 绑定用户 -->
        <el-dialog title="绑定用户" :visible.sync="dialogVisible" width="500px" append-to-body>
            <el-form :model="bindForm" ref="ruleForm" label-width="120px">
                <el-form-item label="选择用户">
                    <customerList v-model="bindForm.id"></customerList>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取消</el-button>
                <el-button type="primary" @click="bindUser">确定</el-button>
            </span>
        </el-dialog>
        <!-- 绑定推广人 -->
        <!-- <el-dialog title="绑定推广人" :visible.sync="dialogVisible1" width="600px" :close-on-click-modal="false" append-to-body>
            <el-form ref="form" :model="promotionForm" label-width="100px">
                <el-form-item label="推广人类型">
                    <el-select v-model="promotionForm.promotionusertype" placeholder="请选择">
                        <el-option v-for="item in promotionusertypeOptions" :key="item.value" :label="item.label"
                            :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="推广人手机号">
                    <el-input v-model="param.salesTel">
                        <el-button slot="append" icon="el-icon-search" @click="checkPromoter">检测</el-button>
                    </el-input>
                </el-form-item>
                <el-form-item label="推广人姓名" v-if="param.name">
                    <span>{{ param.name }}</span>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="bindingPromoter" :disabled="param.btnDisabled">确定</el-button>
                    <el-button @click="dialogVisible1 = false">取消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog> -->
        <!-- 修改名称 -->
        <el-dialog title="修改名称" :visible.sync="editDialogVisible" width="600px" :close-on-click-modal="false" append-to-body>
            <el-form ref="form" label-width="100px">
                <el-form-item label="名称">
                    <el-input v-model="editname"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="confirmEditName">确定</el-button>
                    <el-button @click="editDialogVisible = false">取消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
        <!-- 下载二维码 -->
        <!-- <el-dialog title="下载二维码" :visible.sync="dialogVisible2" width="500px" append-to-body>
            <el-image style="width: 300px; margin: 0 auto;display: block;" :src="codeObj.img"></el-image>
            <div class="text-center e-p-t-20 e-font-18">{{ codeObj.name }}的二维码</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible2 = false">取消</el-button>
                <el-button type="primary" @click="download(codeObj.img, codeObj.name)">下载</el-button>
            </span>
        </el-dialog> -->
        <!-- 批量打印处理 -->
        <!-- <el-dialog title="批量打印" :visible.sync="dialogVisible3" width="500px" append-to-body>
            <el-form ref="form" :model="printform">
                <el-form-item label="每部门打印张数">
                    <el-input v-model="printform.num" type="number"></el-input>
                </el-form-item>
            </el-form>
            <div v-for="(item, index) in printTips" :key="index">
                {{ item }}
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible3 = false" :disabled="printLoading">取消</el-button>
                <el-button type="primary" @click="printAll" :disabled="printLoading">打印</el-button>
            </span>
        </el-dialog> -->
        <!-- 详情页面弹窗(线上用户订单) -->
        <el-drawer
            :visible.sync="viewShow.show"
            direction="rtl"
            size="80%"
            :with-header="false"
            :append-to-body="true"
            >
            <userOrderViews v-if="viewShow.show" :id="viewShow.id" @goBack="viewShow.show = false"></userOrderViews>
        </el-drawer>
        <!-- 详情页面弹窗(线下入库订单详情) -->
        <el-drawer
            :visible.sync="fitViewShow.show"
            direction="rtl"
            size="80%"
            :with-header="false"
            :append-to-body="true"
            >
            <fitOrderViews v-if="fitViewShow.show" :id="fitViewShow.id" @goBack="fitViewShow.show = false"></fitOrderViews>
        </el-drawer>
        <!-- 用户详情页面弹窗 -->
        <el-drawer title="" :visible.sync="userView.show" direction="rtl" size="80%" :with-header="false" :append-to-body="true">
            <userView v-if="userView.show" :id="userView.id" @goBack="userView.show = false"></userView>
        </el-drawer>
    </div>
</template>

<script>
import {
	mapState
} from 'vuex';
// 打印组件引入
import { DTPWeb, LPA_JobNames, LPA_PrintActions } from "dtpweb";
import userOrderViews from '@/components/order-user-list/userOrderViews.vue'
import fitOrderViews from '@/components/order-user-list/fitOrderViews.vue'
import orderUserList from '@/components/order-user-list/order-user-list.vue'
import customerList from '@/components/form-select-type/customerList.vue'
import cityList from '@/components/form-select-type/cityList.vue'
import userView from '@/pages/user/components/views.vue'
// import enterpriseList from '@/components/enterprise-list/enterprise-list.vue'

export default {
    layout: 'admin',
    name: 'enterpriseDetails',
    components:{
        userOrderViews,
        fitOrderViews,
        orderUserList,
        // enterpriseList,
        customerList,
        cityList,
        userView
    },
    head() {
        return {
            title: '客户组详情' 
        }
    },
    props:{
        id:{
            type: [Number, String],
            default: 0
        }  
    },
    data() {
        return {
            loading: false,
            // 用户详情页面弹窗
            userView: {
                id: 0,
                show: false
            },
            // 修改名称
            editDialogVisible: false,
            editname: '',
            tab: 1,
            tabsType: [
                {
                    name: '数据汇总',
                    value: 1
                },
                {
                    name: '下级部门',
                    value: 2
                }
            ],
            // 用户订单（线上）显示
            viewShow:{
                id: 0,
                show: false //详情页面弹窗
            },
            // 用户订单（下线）显示
            fitViewShow:{
                id: 0,
                show: false
            },
            form: {
                department: "",
                name: "",
                userId: '',
                mobile: '',
                id: '',
                enterprisename: '',
                cityId: 0
            },
            tableData: [],//部门列表数据
            department: false,
            details: { //客户组信息
                user:{
                    id: 0
                },
                franchise:{
                    id: 0
                },
                city:{
                    citynames: ''
                },
                integralratio: 0
            },
            orderRecord: {
                balance: 0,
                carbon: 0,
                cashout: 0,
                cashrecord: [],
                income: 0,
                ordercount: 0,
                orderdetails: [],
                orderList: [],
                regdays: 0,
                weight: 0,
            },
            dialogVisible: false,
            userlist: [],
            bindForm: {
                id: null
            },
            dialogVisible2: false,
            codeObj: {
                img: '',
                name: ''
            },

            printers: [{ name: "未检测到打印机", value: {} }],
            // 批量打印处理
            dialogVisible3: false,
            printform: {
                num: 1
            },
            printLoading: false,
            printTips: [],
            multipleSelection: [],
            // 导入excel部门
            fileList: [],
            // 时间选择
            dateForm: {
                timeType: 0,
                timeTypeArr:[
                    {
                        id:0,
                        name: '全部'
                    },
                    {
                        id:1,
                        name: '今日'
                    },
                    {
                        id:2,
                        name: '昨日'
                    },
                    {
                        id:3,
                        name: '本月'
                    },
                    {
                        id:4,
                        name: '上月'
                    },
                    {
                        id:5,
                        name: '本季度'
                    },
                    {
                        id:6,
                        name: '上季度'
                    },
                    {
                        id:7,
                        name: '本年'
                    },
                    {
                        id:8,
                        name: '上年'
                    },
                    {
                        id:9,
                        name: '自定义日期'
                    }
                ],
                date: []
            },
            expireTimeOPtion: {
                disabledDate(time) {
                    return time.getTime() > Date.now() - 8.64e6;  //如果没有后面的-8.64e6就是不可以选择今天的 
                }
            },
            typeArr: [
				{
					name: '全部',
					value: 0
				},
				{
					name: '企业',
					value: 1
				},
				{
					name: '学校',
					value: 2
				},
				{
					name: '机关',
					value: 3
				},
                {
					name: '环卫',
					value: 4
				}
			],
            // // 修改客户组信息
            // edit: {
            //     type: 0
            // }
            editAddress: false,
            statisticsTotal:{
                details: []
            },
        }
    },
    mounted() {
        this.getDetails(this.id)
        this.getEnterpriseStatistics()
        if (this.$route.query.activeName) {
            this.activeName = this.$route.query.activeName
            this.tabsChange({
                name: this.activeName
            })
        }
        // DTPWeb.getInstance().checkPlugin((api) => {
        //     this.api = api;
        //     if (api) {
        //         this.updatePrinterList();
        //     } else {
        //         this.printers[0].name = "未检测到打印插件";
        //     }
        // });
        
    },
    watch: {
        'param.salesTel'(val) {
            console.log(val)
            this.param.name = ''
            // this.myedit = false
            this.param.btnDisabled = true
        },
        department(val) {
            if (val) {
                this.form = {
                    department: "",
                    name: "",
                    // salesTel:'',
                    userId: '',
                    btnDisabled: true,
                    mobile: '',
                    id: '',
                    enterprisename: '',
                    cityId: 0
                }
            }
        }
    },
    computed: {
		...mapState({
			operator: state => state.operator
		})
    },
    methods: {
        // 查看用户详情
        userViews(item){
            this.userView.id = item.id
            this.userView.show = true
        },
        goViewShow(event,row){
            if (event.ctrlKey) {
                console.log('Ctrl + 左键点击');
                // 这里可以执行你需要的操作
                let param = []
                for(let k in this.param){
                    if(this.param[k]){
                        param.push(`${k}=${this.param[k]}`)
                    }
                }
                this.$router.push(`/order/user/list?${param.join('&')}`)
                if (row.terminal == 'AIO') {
                    window.open('/order/brother/fitViews?id=' + row.id, '_blank');
                } else {
                    window.open('/order/user/Views?id=' + row.id, '_blank');
                }
            } else {
                console.log('普通点击');
                if (row.terminal == 'AIO') {
                // return '/order/brother/fitViews?id=' + row.id
                    this.fitViewShow.id = row.id
                    this.fitViewShow.show = true
                } else {
                    this.viewShow.id = row.id
                    this.viewShow.show = true
                }
            }
        },
        edit(){
            if(this.details.parentid == 0){
                this.editname = this.details.name;
            }else{
                this.editname = this.details.department;
            }
            this.editDialogVisible = true
        },
        // 获取详情
        getDetails(id) {
            return this.$axios.get('/Enterprise/Detail?id=' + id).then((res) => {
                console.log(res)
                this.details = res
                // this.orderRecord = res.orders
                // if (res.promotionuser) {
                //     this.promotion = [res.promotionuser]
                // } else {
                //     this.promotion = []
                // }
                this.getSumByType()
                // this.getEnterpriseOrder()
                // this.getWithdrawApply()
            })
        },
        // 绑定客户组
        binding(){
            this.dialogVisible = true
        },
        //解绑客户组
        unbinding() { 
            this.$confirm('您确定要解绑客户组吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$axios.post('/Enterprise/UnBind',[this.id]).then((res) => {
                    this.$message.success(res.msg);
                    this.getDetails(this.id)
                    // this.getOrderRecord(this.id)
                })
            })
        },
        bindUser() { //绑定用户
            this.$axios.post('/Enterprise/Bind', {
                userId: this.bindForm.id,
                id: this.id
            }).then((res) => {
                this.$message.success(res.msg);
                this.getDetails(this.id)
                // this.getOrderRecord(this.id)
                this.dialogVisible = false
            })
        },
        // 更换模式
        changeMode() {
            let type, msg, title
            if (this.details.financemode == '帐户分管') {
                type = 1
                msg = '账户统管模式为，各部门回收余额统一到客户组内，授权给一个部门进行管理'
                title = '是否切换成“账户统管”?'
            } else {
                type = 0
                msg = '账户分管模式为，各部门回收余额分给各部门管理'
                title = '是否切换成“账户分管”?'
            }
            this.$confirm(msg, title, {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.ChangeSettlementType(type)
            }).catch(() => {

            });
        },
        // 切换账户管理模式
        ChangeSettlementType(type) {
            this.$axios.post('/Enterprise/ChangeFinanceMode', {
                "Id": this.details.id,
                "FinanceMode": type
            }).then(() => {
                this.$message.success("更换成功");
                this.getDetails(this.id)
                this.dialogVisible4 = false
            })
        },
        goBack() {
            this.$emit('goBack')
        },
        // 选择时间筛选回收汇总
        chageTime(e){
            let param = {
                timeType: this.dateForm.timeType,
                enterpriseId: this.id,
                orderType: null, //订单类型：0全部，1.线上单，2.线下单
                userType: 1, //用户类型：0全部，1客户组订单，2用户订单
                includeDepartment: true, //是否包含下级部门(EnterpriseId>0时有效)
            }

            // 判断是否为自定义时间筛选回收统计
            if(this.dateForm.timeType == 9){
                this.dateForm.startDate = e[0]
                this.dateForm.endDate = e[1]

                try {
                    param.startDate = this.dateForm.startDate
                    param.endDate = this.dateForm.endDate
                } catch (e) {
                    console.log('选择自定义日期筛选回收统计错误：',e)
                }
                
                if(!param.startDate||!param.endDate){
                    return
                }
            }else{
                this.dateForm.date = []
            }
            
            this.getSumByType(param)
            this.getEnterpriseStatistics()
        },
        // 客户组（企业）统计
        getEnterpriseStatistics() { 
            let param = {
                timeType: this.dateForm.timeType,
                enterpriseId: this.id,
            }

            // 判断是否为自定义时间筛选回收统计
            if(this.dateForm.timeType == 9){
                try {
                    param.start = this.dateForm.startDate
                    param.end = this.dateForm.endDate
                } catch (e) {
                    console.log('选择自定义日期筛选回收统计错误：',e)
                }
                
                if(!param.start||!param.end){
                    return
                }
            }else{
                this.dateForm.date = []
            }

            this.$axios.post('/Statistics/Enterprise/Index',param).then((res)=>{
                this.statisticsTotal = res
                this.statisticsTotal.details = this.statisticsTotal.details.filter((item)=>item.amount > 0)
            })
        },
        // 下载客户组（企业）统计
        downloadwithdrawa() {

            let param = {
                timeType: this.dateForm.timeType,
                enterpriseId: this.id,
            }

            // 判断是否为自定义时间筛选回收统计
            if(this.dateForm.timeType == 9){
                try {
                    param.start = this.dateForm.startDate
                    param.end = this.dateForm.endDate
                } catch (e) {
                    console.log('选择自定义日期筛选回收统计错误：',e)
                }
                
                if(!param.start||!param.end){
                    return
                }
            }else{
                this.dateForm.date = []
            }
            this.$axios.post('/Statistics/Enterprise/Download', param, {
                responseType: 'blob'
            }).then(res => {
                console.log(res)
                let content = res;
                let fileName = this.details.name+'回收统计.xls'
                this.utils.saveAndExport(content, fileName)
            })
        },
        getSumByType(param = null){
            if(param == null){
                param = {
                    timeType: this.dateForm.timeType,
                    enterpriseId: this.id,
                    orderType: null, //订单类型：null全部，1.线上单，2.线下单
                    userType: 1, //用户类型：0全部，1客户组订单，2用户订单
                    includeDepartment: this.details.parentid > 0?false:true, //是否包含下级部门(EnterpriseId>0时有效)
                }
            }
            console.log('getSumByType.param',param)
            this.$axios.post(`/User/Order/SumByType`,param).then((res)=>{
                console.log('SumByType',res)
                // this.orderRecord.orderdetails = res.largetype
                let dataArray = []
                res.type.forEach((item,index)=>{
                    item.product.forEach((cell,i)=>{
                        dataArray.push({
                            id: cell.id,
                            typeId: cell.typeId,
                            name: cell.name,
                            quantity: cell.quantity,
                            weight: cell.weight,
                            amount: cell.amount,
                            large: item.name,
                            sort: cell.sort,
                            isweighing: cell.isweighing
                        })
                    })
                })

                this.orderRecord.orderdetails = dataArray
                this.orderRecord.amount = res.amount // 总金额
                this.orderRecord.weight = res.weight // 总重量
                this.orderRecord.carbon = res.carbon //总减碳量
                this.orderRecord.quantity = res.quantity // 总件数
                this.orderRecord.onlinecount = res.onlinecount // 统计线上单数量
                this.orderRecord.offlinecount = res.offlinecount // 统计线下单数量
            })
        },
        //合并类型格子
        objectSpanMethod({ row, column, rowIndex, columnIndex }) {
            let mergeLength = [0];//需要进行横纵合并的列,0开始
            for (let j = 0; j < mergeLength.length; j++) {
                if (columnIndex == mergeLength[j]) {
                    let finArray = [1, 1];
                    // 处理行数据
                    let cgname = 'large' //合并单元格的主键依据，一般为第一列的值
                    if (rowIndex === 0 || row[cgname] !== this.orderRecord.orderdetails[rowIndex - 1][cgname]) {
                        let rowspan = 1;
                        //计算需要进行合并操作的行
                        for (let i = 0; i < this.orderRecord.orderdetails.length - 1; i++) {
                            // 只合并连续的
                            if (this.orderRecord.orderdetails[i][cgname] === row[cgname] && this.orderRecord.orderdetails[i + 1][cgname] === row[cgname]) {
                                rowspan++;
                            }
                        }
                        finArray[0] = rowspan;
                    } else {
                        finArray[0] = 0;
                    }
                    return finArray
                }
            }
        },
        //合并最后一个合计
        getSummaries(param) {
            const sums = []
            sums[0] = '合计'
            sums[1] = '/'
            sums[2] = (this.orderRecord.weight).toFixed(2) + 'KG' + ' / ' + this.orderRecord.quantity + '件'
            sums[3] = this.orderRecord.amount
            return sums;
            // sums数组的每一个元素代表表格从左到右的列(column)。
        },
        // 修改该客户组的积分比例
        updateIntegralRatio(){
            this.$axios.post(`/Enterprise/UpdateIntegralRatio`,{
                id: this.id,
                integralRatio: this.details.integralratio
            }).then((res)=>{
                this.$message.success('修改成功')
            })
        },
        // 修改该客户组的分类
        updateEnterpriseType(){
            this.$axios.post(`/Enterprise/UpdateType`,{
                Type: this.details.type,
                Id: this.id
            }).then((res)=>{
                this.$message.success('修改成功')
            })
        },
        // 修改客户组地区
        SelectSearchCity(v) { //选择城市
            this.$axios.post('/Enterprise/Edit', {
                id: this.id,
                name: this.details.name,
                cityId: v,
            }).then((res) => {
                this.$message.success('修改地区成功')
                this.getDetails(this.id)
            })
        },
        // 修改名称
        confirmEditName() { 
            this.$axios.post('/Enterprise/Edit', {
                id: this.id,
                name: this.editname,
                cityId: 0,
            }).then((res) => {
                this.$message.success('修改名称成功')
                this.getDetails(this.id)
                this.editDialogVisible = false
            })
        },
    }
}
</script>

<style lang="scss" scoped>
.user-basic-box {
    // background: url(/images/bg.jpg);
    background-size: 100%;
    text-align: center;

    .user-face {
        text-align: center;
        width: 100px;
        margin: 0 auto;
        position: relative;

        .avatar {
            .iconfont {
                font-size: 14px;
                position: absolute;
                right: 3px;
                bottom: 26px;
                background-color: #fff;
                height: 22px;
                width: 22px;
                line-height: 24px;
                border-radius: 100%;
            }

            .male {
                background: var(--blue);
                color: #fff;
            }

            .female {
                background: var(--pink);
                color: #fff;
            }
        }
    }

    .basic {
        font-size: 14px;
        align-items: center;
        justify-content: center;
        margin-top: 15px;

        .item {
            margin: 0 10px;
        }
    }
}


.admin-statistics-content {
    display: flex;

    .item {
        &+.item {
            border-left: 1px solid var(--light);
            padding-left: 30px;
        }

        .icon {
            width: 44px;
            height: 44px;
            border-radius: 50%;
            border: 1px solid var(--light);
            background-color: #f2f3f5;
            padding: 5px;
            margin: 0 20px 0 0;
            box-shadow: 3px 2px 11px 0 rgb(70 70 70 / 22%);
        }

        label {
            color: var(--grey);
            font-size: 12px;
            margin-bottom: 5px;
            display: block;
        }

        .num {
            font-size: 30px;
        }
    }
}

.statistics-content {
    display: flex;

    .item {
        &+.item {
            border-left: 1px solid var(--light);
            padding-left: 30px;
        }

        .icon {
            width: 44px;
            height: 44px;
            border-radius: 50%;
            border: 1px solid var(--light);
            background-color: #f2f3f5;
            padding: 5px;
            margin: 0 20px 0 0;
            box-shadow: 3px 2px 11px 0 rgb(70 70 70 / 22%);
        }

        label {
            color: var(--grey);
            font-size: 12px;
            margin-bottom: 5px;
            display: block;
        }

        .num {
            font-size: 30px;
        }
    }
}
</style>
